package com.mf.ergate.web.controller.monitor;

import com.mf.ergate.api.monitor.model.dto.LoginLogQueryDto;
import com.mf.ergate.api.monitor.model.vo.LoginLogVo;
import com.mf.ergate.web.common.utils.MfParamUtils;
import com.mf.ergate.web.domain.enums.generic.AppTypeEnum;
import com.mf.ergate.web.service.monitor.LoginLogService;
import com.mf.framework.common.model.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 登录日志Controller
 * User: zhaoming
 * DateTime: 2019-02-12
 * To change this template use File | Settings | File Templates.
 */
@Secured({"MANAGE_LOGIN_LOG"})
@Controller
@RequestMapping("/web/loginLog")
public class LoginLogController{

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private LoginLogService loginLogService;

    /**
     * 首页
     * @return 模型视图
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("monitor/login/login_log_index");
        // 应用类型
        modelAndView.addObject("AppTypeEnum", AppTypeEnum.getList());
        return modelAndView;
    }

    /**
     * 根据业务主键查询
     * @param uniqueNo 唯一编号
     * @return 登录日志
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public LoginLogVo detail(String uniqueNo) {
        return loginLogService.selectByUniqueNo(uniqueNo);
    }

    /**
     * 根据条件分页查询
     * @param loginLogQueryDto 登录日志查询
     * @param pageNum 当前页码
     * @param pageSize 每页显示条数
     * @param sortName 排序字段
     * @param sortOrder 排序方式
     * @return 登录日志分页列表
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Page<LoginLogVo> page(LoginLogQueryDto loginLogQueryDto,
                                 @RequestParam(value = "page") int pageNum,
                                 @RequestParam(value = "rows") int pageSize,
                                 @RequestParam(value = "sidx") String sortName,
                                 @RequestParam(value = "sord") String sortOrder) {

        Page page = MfParamUtils.buildPage(pageNum, pageSize, sortName, sortOrder);
        return loginLogService.selectPage(page, loginLogQueryDto);
    }

}